#!/usr/bin/env python

import sys, urllib2, datetime
from optparse import OptionParser

def check(qqnum):
    url = 'http://wpa.qq.com/pa?p=1:' + str(qqnum) + ':1'
    res = urllib2.urlopen(url)
    length = res.headers.get("content-length")
    res.close()
    if length == '2329':
        return 'online'   
    elif length == '2262':
        return 'offline'
    else:
        return 'unknown'

def main():
    parser = OptionParser(usage = '%prog [options]')
    parser.add_option('-n', '--number', default = '491849118',
            help = 'qq number')
    options, args = parser.parse_args()
    print datetime.datetime.now()
    print check(options.number)

if __name__ == '__main__':
    sys.exit(main())
